Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-tag

Package Overview
Dependencies
Maintainers
6
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-tag

A JavaScript template literal tag that parses GraphQL queries

  • 1.3.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created

What is graphql-tag?

The graphql-tag npm package is primarily used for parsing GraphQL queries and fragments into a standard GraphQL AST (Abstract Syntax Tree). It is commonly used in JavaScript or TypeScript projects that interact with a GraphQL server. The package provides a simple and efficient way to embed GraphQL queries within the code.

What are graphql-tag's main functionalities?

Parsing GraphQL queries

This feature allows developers to write GraphQL queries inside JavaScript or TypeScript files using template literals. The gql function parses the query string into a GraphQL AST, which can then be used with GraphQL clients like Apollo Client.

import gql from 'graphql-tag';

const MY_QUERY = gql`
  query GetUserInfo($userId: ID!) {
    user(id: $userId) {
      id
      name
      email
    }
  }
`;

Parsing GraphQL fragments

This feature allows the definition of GraphQL fragments that can be reused across multiple queries or mutations. The gql function is used to parse the fragment, and it can be embedded within queries or mutations to avoid repetition of field definitions.

import gql from 'graphql-tag';

const USER_FRAGMENT = gql`
  fragment UserFragment on User {
    id
    name
    email
  }
`;

const MY_QUERY = gql`
  query GetUserInfo($userId: ID!) {
    user(id: $userId) {
      ...UserFragment
    }
  }
  ${USER_FRAGMENT}
`;

Support for multiple operations in a single document

graphql-tag supports defining multiple operations, such as queries and mutations, within a single gql template literal. This can be useful for organizing related operations together in one place.

import gql from 'graphql-tag';

const MULTIPLE_OPERATIONS = gql`
  query GetUserInfo($userId: ID!) {
    user(id: $userId) {
      id
      name
    }
  }

  mutation UpdateUserName($userId: ID!, $newName: String!) {
    updateUser(id: $userId, name: $newName) {
      id
      name
    }
  }
`;

Other packages similar to graphql-tag

FAQs

Package last updated on 21 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc